<template>
  <transition name="slide">
    <div class="modal" v-show="showModal">
      <div class="mask">
        <div class="modal-dialog">
          <div class="modal-header">
            <span>{{ title }}</span>
            <a
              href="javascript:;"
              class="icon-close"
              @click="$emit('cancel')"
            ></a>
          </div>
          <div class="modal-body">
            <slot name="body"></slot>
          </div>
          <div class="modal-footer">
            <a
              href="javascript:;"
              class="btn"
              v-if="btnType == 1"
              @click="$emit('submit')"
              >{{ sureText }}</a
            >
            <a
              href="javascript:;"
              class="btn"
              v-if="btnType == 2"
              @click="$emit('cancel')"
              >{{ cancelText }}</a
            >
            <div class="btn-group" v-if="btnType == 3">
              <a href="javascript:;" class="btn" @click="$emit('submit')">{{
                sureText
              }}</a>
              <a
                href="javascript:;"
                class="btn btn-default"
                @click="$emit('cancel')"
                >{{ cancelText }}</a
              >
            </div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    //弹框的大小。小中大表单。
    modalType: {
      type: String,
      default: "form",
    },
    title: String,
    //按钮类型，1.确认按钮，2.取消按钮，3.确认取消
    btnType: String,
    sureText: {
      type: String,
      default: "确定",
    },
    cancelText: {
      type: String,
      default: "取消",
    },
    showModal: Boolean,
  },
};
</script>

<style lang="scss">
@import "../assets/scss/config.scss";
@import "../assets/scss/mixin.scss";
@import "../assets/scss/modal.scss";
@import "../assets/scss/button.scss";
.modal {
  @include position(fixed);
  z-index: 10;
  transition: all 0.5s;
  &.slide-enter-active {
    top: 0;
  }
  &.slide-leave-active {
    top: -100%;
  }
  &.slide-enter {
    top: -100%;
  }
  .mask {
    @include position(fixed);
    background-color: rgba(0, 0, 0, 0.5);
  }
  .modal-dialog {
    @include position(fixed, 40%, 50%, 660px, auto);
    background-color: #ffffff;
    transform: translate(-50%, -50%); //x,y轴偏移
    .modal-header {
      height: 60px;
      background-color: #f5f5f5;
      padding: 0px 25px;
      font-size: 16px;
      line-height: 60px;
      .icon-close {
        @include positionImg(
          absolute,
          23px,
          25px,
          14px,
          14px,
          "/imgs/icon-close.png"
        );
        transition: transform 0.3s; //动态效果顺滑一些
        &:hover {
          transform: scale(1.5); //放大的效果。
        }
      }
    }
    .modal-body {
      padding: 42px 40px 45px;
      font-size: 14px;
      text-align: center;
    }
    .modal-footer {
      height: 82px;
      line-height: 82px;
      text-align: center;
      background-color: #f5f5f5;
    }
  }
}
</style>
